package com.csap.framework.oauth2.security.servlet.boot;

import cn.dev33.satoken.stp.StpInterface;
import com.csap.framework.oauth2.security.Oauth2SecurityProperties;
import com.csap.framework.oauth2.security.SecurityExceptionHandler;
import com.csap.framework.oauth2.security.servlet.Oauth2SecurityServletConfigurer;
import com.csap.framework.oauth2.security.user.SecurityStpInterfaceImpl;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author yangchengfu
 * @dataTime 2021年-07月-27日 22:46:00
 **/
@Configuration
@ConditionalOnProperty(prefix = Oauth2SecurityProperties.PREFIX, value = "enabled", havingValue = "true")
@ImportAutoConfiguration(Oauth2SecurityServletConfigurer.class)
@ComponentScan("com.csap.framework.oauth2.security")
public class Oauth2SecurityServletAutoConfigurer {

    @Primary
    @Bean
    @ConditionalOnMissingBean
    public SecurityExceptionHandler securityExceptionHandler() {
        return new SecurityExceptionHandler();
    }

    @Bean
    @ConditionalOnMissingBean
    public StpInterface stpInterface() {
        return new SecurityStpInterfaceImpl();
    }
}
